package org.sharing.design.strategy.onStrategy.impl;

import org.sharing.design.strategy.onStrategy.ICouponDiscount;

import java.math.BigDecimal;

/**
 * @author: Dragon
 * @since: 2024/4/6 16:09
 */
public class ZKCouponDiscount implements ICouponDiscount<Double> {

    /**
     * 折扣计算
     * @param couponInfo
     * @param price
     * @return
     */
    @Override
    public BigDecimal discountAmount(Double couponInfo, BigDecimal price) {
        BigDecimal discountAmount = price.multiply(new BigDecimal(couponInfo)).setScale(2, BigDecimal.ROUND_HALF_UP);
        if (discountAmount.compareTo(BigDecimal.ZERO) < 1) return BigDecimal.ONE;
        return discountAmount;
    }
}
